<?php

/*
 * Author : Andi Kurniawan
 * Follow me : @nakamichikun
 */

class Modmem extends CI_Model {

    // Store to database
    function setMessage($data) {
        $this->db->insert('proses', $data);
    }

    // Authentication user
    function authentic($data) {
        $this->db->where('username', $data['username']);
        $this->db->where('password', $data['password']);
        $this->db->where('status', 1);
        $data = $this->db->get('user');
        if ($data->num_rows > 0) {
            return $data->row();
        } else {
            $array = array(
                'username' => '',
                'password' => ''
            );
            $data = (object) $array;
            return $data;
        }
    }

    function login($data) {
        $this->db->where('username', $data['username']);
        $this->db->where('password', $data['password']);
        $data = $this->db->get('user');
        if ($data->num_rows > 0) {
            return $data = TRUE;
        } else {
            return $data = FALSE;
        }
    }

    function role($data) {
        $this->db->where('username', $data['username']);
        $this->db->where('role', $data['access']);
        $data = $this->db->get('user_role');
        if ($data->num_rows > 0) {
            return $data = TRUE;
        } else {
            return $data = FALSE;
        }
    }

    function getPesan() {
        $this->db->where('akses', 0);
        $data = $this->db->get('proses');
        if ($data->num_rows > 0) {
            return $data->result();
        } else {
            return $data = NULL;
        }
    }

    function updPesan($id) {
        $this->db->where('id', $id);
        $this->db->update('proses', array('akses' => 1));
    }

}

?>
